package com.ruoyi.project.custom.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.common.utils.SnowflakeIdWorker;
import com.ruoyi.project.custom.domain.CustomContact;
import com.ruoyi.project.custom.service.ICustomContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-06-26
 */
@RestController
@RequestMapping("/custom/contact")
public class CustomContactController extends BaseController
{
    @Autowired
    private ICustomContactService customContactService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CustomContact customContact)
    {
        startPage();
        List<CustomContact> list = customContactService.selectCustomContactList(customContact);
        return getDataTable(list);
    }

    @GetMapping("/selectCustomContactByCustomId/{customId}")
    public TableDataInfo selectCustomContactByCustomId(@PathVariable("customId") String customId)
    {
        startPage();
        List<CustomContact> list = customContactService.selectCustomContactByCustomId(customId);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CustomContact customContact)
    {
        List<CustomContact> list = customContactService.selectCustomContactList(customContact);
        ExcelUtil<CustomContact> util = new ExcelUtil<CustomContact>(CustomContact.class);
        return util.exportExcel(list, "contact");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(customContactService.selectCustomContactById(id));
    }

    /**
     * 新增【请填写功能名称】
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomContact customContact)
    {
        customContact.setId(SnowflakeIdWorker.generateId().toString());
        customContactService.insertCustomContact(customContact);
        return AjaxResult.success("新增成功", customContact.getId());
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomContact customContact)
    {
        return toAjax(customContactService.updateCustomContact(customContact));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(customContactService.deleteCustomContactByIds(ids));
    }
}
